﻿package com.medic.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.medic.entity.Doctor;
import com.medic.entity.User;
import com.medic.entity.Weichat;
import com.medic.service.impl.DoctorServiceImpl;
import com.medic.service.impl.UserServiceImpl;
import com.medic.entity.Weichat;
import com.medic.util.CacheUtil;
import com.medic.util.LoggerUtil;
import com.medic.util.StringUtil;

public class ClientLoginParamInterceptor extends HandlerInterceptorAdapter {

	private final String appIdKey = "appId";
	private final String userKey = "user";
	private final String doctorKey = "doctor";
	private final String weichatKey = "weichat";

	@Resource(name = "userService")
	private UserServiceImpl userService;
	@Resource(name = "doctorService")
	private DoctorServiceImpl doctorService;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		Weichat weichat = new Weichat();
		weichat.setOpenid("openId");
		//User user = userService.getUser(1);
		//LoggerUtil.debug(user.toString());
		Doctor doctor = doctorService.getDoctor(1);
		request.getSession().setAttribute(appIdKey, CacheUtil.getConfig().getProperty(StringUtil.APP_ID));
		//request.getSession().setAttribute(userKey, user);

		
		//request.getSession().setAttribute(doctorKey, doctor);
		// LoggerUtil.debug(user.getId() + "--------");

//		request.getSession().setAttribute("isuser", "true");
//		Weichat w=new Weichat();
//		w.setId(1);
//		w.setRole("user");
//		w.setRoleid(1);
//		w.setRolename("阿西吧");
//		request.getSession().setAttribute("weichat",w);
		
		//request.getSession().setAttribute(weichatKey, weichat);
		
		//request.getSession().setAttribute(doctorKey, doctor);
		//LoggerUtil.debug(user.getId() + "--------");

		return super.preHandle(request, response, handler);
	}

}
